package com.kara.woodAgent.agent.memory.impl;

import com.kara.woodAgent.agent.memory.EmbeddingStoreProvider;
import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.elasticsearch.ElasticsearchConfigurationScript;
import dev.langchain4j.store.embedding.elasticsearch.ElasticsearchEmbeddingStore;
import org.apache.http.Header;
import org.apache.http.HttpHost;
import org.apache.http.message.BasicHeader;
import org.elasticsearch.client.RestClient;
import org.springframework.boot.autoconfigure.jms.artemis.ArtemisProperties;
import org.springframework.stereotype.Component;

/**
 * @author tzy
 * @version 1.0
 * @project wood_agent
 * @description todo
 * @date 2025/6/9 14:32:48
 */
@Component
public class EsEmbeddingStoreProvider implements EmbeddingStoreProvider {
	@Override
	public EmbeddingStore<TextSegment> getEmbeddingStore() {

		String apiKey = "VnVhQ2ZHY0JDZGJrU...";
		RestClient restClient = RestClient
				.builder(HttpHost.create("https://localhost:9200"))
				.setDefaultHeaders(new Header[]{
						new BasicHeader("Authorization", "ApiKey " + apiKey)
				})
				.build();

		return ElasticsearchEmbeddingStore.builder()
				.configuration(ElasticsearchConfigurationScript.builder().build())
				.restClient(restClient)
				.build();
	}
}
